<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/20
 * Time: 10:38
 */

namespace App\Http\Controllers\MiniProgramAdmin;


use App\Http\Logics\MiniProgramAdmin\MenuLogic;
use App\Http\Traits\MenuTrait;
use App\Menu;
use App\Http\Controllers\BaseController;
class MenuController extends BaseController
{
    use MenuTrait;
    /**
     * @SWG\Get(
     *     path="/menu/getListByUserId",
     *     tags={"Menu"},
     *     description="通过用户ID获取该用户的管理菜单",
     *     operationId="getMenuListByUserId",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥，并且通过loginSession获取合作者信息",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="user_id",
     *         in="query",
     *         description="用户ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getMenuListByUserId()
    {
        $user_id = $this->user_id;
        $key = $this->key;
        $data = [
            'user_id' => $user_id
        ];
        $response = MenuLogic::getMenuListByUserId($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/menu/updateByUserId",
     *     tags={"Menu"},
     *     description="通过用户ID更新该用户的管理菜单及角色名称",
     *     operationId="updateMenuByUserId",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="user_id",
     *         in="query",
     *         description="用户ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="menu_id_str",
     *         in="query",
     *         description="菜单ID字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function updateMenuByUserId()
    {
        $user_id = $this->user_id;
        $menu_id_str = $this->menu_id_str;
        $data = [
            'user_id' => $user_id,
            'menu_id_str' => $menu_id_str
        ];
        $response = MenuLogic::updateMenuByUserId($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/menu/getListHasQrcode",
     *     tags={"Menu"},
     *     description="获取拥有二维码的菜单列表",
     *     operationId="getMenuListHasQrcode",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getMenuListHasQrcode()
    {
        $loginSession = $this->loginSession;
        $data = [
            'loginSession' => $loginSession,
            'has_qrcode' => Menu::HAS_QRCODE
        ];
        $response = MenuLogic::getMenuListHasQrcode($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}